package hc.bre.cmn

import java.lang.reflect.ParameterizedType

import hc.bre.data.setting.SettingItem

@groovy.transform.CompileStatic
@groovy.transform.ToString(includeNames=true,includePackage=false)
class TreeOption<T extends TreeOption<T>> extends ListOption implements ITreeNode<T>{
	List<T> list;

	@Override
	public T load(Map map) {

		super.load(map);

		List<Map> lst = map['list'] as List<Map>;

		if(lst == null) this.list = null;
		else {
			this.list = lst.collect(){Map it-> newOption().load(it) }
		}

		return this;
	}

	T newOption() {
		ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
		Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
		def newD = clazz.newInstance();
		return newD;
	}
}
